class Admin::LoginController < Admin::BaseController
	
	
  def show
    #render :layout => false
  end
  
  def login
    username = params[:username]
    password = params[:password]

    #超级帐户登录
    if (username == "admin" && password == "admin")
      session[:admin] = username
      session[:admin_id] = 0
      redirect_to(:controller=> 'admin/administrator', :action => 'list')
      return
    end

    #简化业务代码 && 增加自动返回验证点的代码
    unless(session[:admin].nil? && username.nil? && password.nil?)
      admin = Administrator.login username, password
      if(admin)
        session[:admin] = username
        session[:admin_id] = admin.id
        before_auth = session[:before_auth] || {:controller=> 'admin/administrator', :action => 'list'}
        session[:before_auth] = nil
        redirect_to(before_auth)
        return
      end
    end
    
    redirect_to :action => 'index'
  end
  
  def logout
    session[:admin] = nil
    session[:admin_id] = nil
    redirect_to(:action => 'index')
  end
end
